<template>
  <div class="app-container">
    <!-- <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="学院高基ID" prop="baseCollegeId">
        <el-input
          v-model="queryParams.baseCollegeId"
          placeholder="请输入学院高基ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学院代码" prop="orgCode">
        <el-input
          v-model="queryParams.orgCode"
          placeholder="请输入学院代码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="仪器编号" prop="number">
        <el-input
          v-model="queryParams.number"
          placeholder="请输入仪器编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="分类号" prop="classifyNumber">
        <el-input
          v-model="queryParams.classifyNumber"
          placeholder="请输入分类号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="仪器名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入仪器名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单价" prop="price">
        <el-input
          v-model="queryParams.price"
          placeholder="请输入单价"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="型号" prop="model">
        <el-input
          v-model="queryParams.model"
          placeholder="请输入型号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="规格" prop="specs">
        <el-input
          v-model="queryParams.specs"
          placeholder="请输入规格"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="教学机时" prop="teachHours">
        <el-input
          v-model="queryParams.teachHours"
          placeholder="请输入教学机时"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="科研机时" prop="scientificHours">
        <el-input
          v-model="queryParams.scientificHours"
          placeholder="请输入科研机时"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="社会服务机时" prop="socialServiceHours">
        <el-input
          v-model="queryParams.socialServiceHours"
          placeholder="请输入社会服务机时"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开放使用机时" prop="openUserHours">
        <el-input
          v-model="queryParams.openUserHours"
          placeholder="请输入开放使用机时"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="测样数" prop="sampleNumber">
        <el-input
          v-model="queryParams.sampleNumber"
          placeholder="请输入测样数"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="培训学生数" prop="trainStudentNumber">
        <el-input
          v-model="queryParams.trainStudentNumber"
          placeholder="请输入培训学生数"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="培训教师数" prop="trainTeacherNumber">
        <el-input
          v-model="queryParams.trainTeacherNumber"
          placeholder="请输入培训教师数"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="培训其他数" prop="trainOtherNumber">
        <el-input
          v-model="queryParams.trainOtherNumber"
          placeholder="请输入培训其他数"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="教学实验项目数" prop="teachProjectNumber">
        <el-input
          v-model="queryParams.teachProjectNumber"
          placeholder="请输入教学实验项目数"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="科研项目数" prop="scientificProjectNumber">
        <el-input
          v-model="queryParams.scientificProjectNumber"
          placeholder="请输入科研项目数"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="社会服务项目数" prop="socialServiceProjectNumber">
        <el-input
          v-model="queryParams.socialServiceProjectNumber"
          placeholder="请输入社会服务项目数"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="国家级获奖数" prop="nationalAwardsNumber">
        <el-input
          v-model="queryParams.nationalAwardsNumber"
          placeholder="请输入国家级获奖数"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="省级获奖数" prop="provincialAwardsNumber">
        <el-input
          v-model="queryParams.provincialAwardsNumber"
          placeholder="请输入省级获奖数"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="教师专利数" prop="teacherPatentNumber">
        <el-input
          v-model="queryParams.teacherPatentNumber"
          placeholder="请输入教师专利数"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学生专利数" prop="studentPatentNumber">
        <el-input
          v-model="queryParams.studentPatentNumber"
          placeholder="请输入学生专利数"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="三大检索论文数" prop="threeRetrievalPapers">
        <el-input
          v-model="queryParams.threeRetrievalPapers"
          placeholder="请输入三大检索论文数"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="核心刊物论文数" prop="coreJournalPapers">
        <el-input
          v-model="queryParams.coreJournalPapers"
          placeholder="请输入核心刊物论文数"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="负责人" prop="chargePerson">
        <el-input
          v-model="queryParams.chargePerson"
          placeholder="请输入负责人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form> -->

    <!-- <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['statistics:statisticsEquipment:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['statistics:statisticsEquipment:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['statistics:statisticsEquipment:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['statistics:statisticsEquipment:export']"
        >导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row> -->
  <el-button
          type="primary"
          icon="el-icon-upload"
          size="mini"
          @click="handleImport"
        >导入</el-button>
    <el-dialog title="基表三数据导入" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :action="upload.url"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :disabled="upload.isUploading"
        :auto-upload="false"
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <div class="el-upload__tip" slot="tip">
          </div>
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
    <el-table v-loading="loading" :data="detailList" height="480px" @selection-change="handleSelectionChange">
      <!-- <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="id" />
      <el-table-column label="学院高基ID" align="center" prop="baseCollegeId" /> -->
      <el-table-column label="学院代码" align="left" width="120px" prop="orgCode" />
      <el-table-column label="仪器编号" align="left" width="120px" prop="number" />
      <el-table-column label="分类号" align="left" width="120px" prop="classifyNumber" />
      <el-table-column label="仪器名称" align="left" width="120px" prop="name" />
      <el-table-column label="单价" align="center" prop="price" />
      <el-table-column label="型号" align="center" prop="model" />
      <el-table-column label="规格" align="center" prop="specs" />
      <el-table-column label="使用机时" align="center">
        <el-table-column label="教学" align="center" prop="teachHours" />
        <el-table-column label="科研" align="center" prop="scientificHours" />
        <el-table-column label="社会服务" align="center" prop="socialServiceHours" />
        <el-table-column label="开放使用" align="center" prop="openUserHours" />
      </el-table-column>
      <el-table-column label="测样数" align="center" prop="sampleNumber" />
      <el-table-column label="使用机时" align="center">
        <el-table-column label="学生" align="center" prop="trainStudentNumber" />
        <el-table-column label="教师" align="center" prop="trainTeacherNumber" />
        <el-table-column label="其他" align="center" prop="trainOtherNumber" />
      </el-table-column>
      <el-table-column label="教学实验项目数" align="center" prop="teachProjectNumber" />
      <el-table-column label="科研项目数" align="center" prop="scientificProjectNumber" />
      <el-table-column label="社会服务项目数" align="center" prop="socialServiceProjectNumber" />
      <el-table-column label="获奖情况" align="center">
        <el-table-column label="国家级" align="center" prop="nationalAwardsNumber" />
        <el-table-column label="省级" align="center" prop="provincialAwardsNumber" />
      </el-table-column>
      <el-table-column label="发明专利" align="center">
        <el-table-column label="教师" align="center" prop="teacherPatentNumber" />
        <el-table-column label="学生" align="center" prop="studentPatentNumber" />
      </el-table-column>
      <el-table-column label="论文情况" align="center">
        <el-table-column label="三大检索" align="center" prop="threeRetrievalPapers" />
        <el-table-column label="核心刊物" align="center" prop="coreJournalPapers" />
      </el-table-column>
      <el-table-column label="负责人" align="center" prop="chargePerson" />
      <el-table-column label="所在单位" align="center" prop="department" />
      <el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >修改</el-button>
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
          >删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>

    <!-- <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    /> -->

    <!-- 添加或修改贵重仪器设备对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :inline=true :rules="rules" label-width="120px" style="height: 480px; overflow: auto;">
        <!-- <el-form-item label="学院高基ID" prop="baseCollegeId">
          <el-input v-model="form.baseCollegeId" placeholder="请输入学院高基ID" />
        </el-form-item> -->
        <el-form-item label="学院代码" prop="orgCode">
          <el-input v-model="form.orgCode" placeholder="请输入学院代码" disabled />
        </el-form-item>
        <el-form-item label="仪器编号" prop="number">
          <el-input v-model="form.number" placeholder="请输入仪器编号" disabled/>
        </el-form-item>
        <el-form-item label="分类号" prop="classifyNumber">
          <el-input v-model="form.classifyNumber" placeholder="请输入分类号" disabled/>
        </el-form-item>
        <el-form-item label="仪器名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入仪器名称" disabled/>
        </el-form-item>
        <el-form-item label="单价" prop="price">
          <el-input v-model="form.price" placeholder="请输入单价" />
        </el-form-item>
        <el-form-item label="型号" prop="model">
          <el-input v-model="form.model" placeholder="请输入型号" disabled/>
        </el-form-item>
        <el-form-item label="规格" prop="specs">
          <el-input v-model="form.specs" placeholder="请输入规格" disabled/>
        </el-form-item>
        <el-form-item label="教学机时" prop="teachHours">
          <el-input v-model="form.teachHours" placeholder="请输入教学机时" />
        </el-form-item>
        <el-form-item label="科研机时" prop="scientificHours">
          <el-input v-model="form.scientificHours" placeholder="请输入科研机时" />
        </el-form-item>
        <el-form-item label="社会服务机时" prop="socialServiceHours">
          <el-input v-model="form.socialServiceHours" placeholder="请输入社会服务机时" />
        </el-form-item>
        <el-form-item label="开放使用机时" prop="openUserHours">
          <el-input v-model="form.openUserHours" placeholder="请输入开放使用机时" />
        </el-form-item>
        <el-form-item label="测样数" prop="sampleNumber">
          <el-input v-model="form.sampleNumber" placeholder="请输入测样数" />
        </el-form-item>
        <el-form-item label="培训学生数" prop="trainStudentNumber">
          <el-input v-model="form.trainStudentNumber" placeholder="请输入培训学生数" />
        </el-form-item>
        <el-form-item label="培训教师数" prop="trainTeacherNumber">
          <el-input v-model="form.trainTeacherNumber" placeholder="请输入培训教师数" />
        </el-form-item>
        <el-form-item label="培训其他数" prop="trainOtherNumber">
          <el-input v-model="form.trainOtherNumber" placeholder="请输入培训其他数" />
        </el-form-item>
        <el-form-item label="教学实验项目数" prop="teachProjectNumber">
          <el-input v-model="form.teachProjectNumber" placeholder="请输入教学实验项目数" />
        </el-form-item>
        <el-form-item label="科研项目数" prop="scientificProjectNumber">
          <el-input v-model="form.scientificProjectNumber" placeholder="请输入科研项目数" />
        </el-form-item>
        <el-form-item label="社会服务项目数" prop="socialServiceProjectNumber">
          <el-input v-model="form.socialServiceProjectNumber" placeholder="请输入社会服务项目数" />
        </el-form-item>
        <el-form-item label="国家级获奖数" prop="nationalAwardsNumber">
          <el-input v-model="form.nationalAwardsNumber" placeholder="请输入国家级获奖数" />
        </el-form-item>
        <el-form-item label="省级获奖数" prop="provincialAwardsNumber">
          <el-input v-model="form.provincialAwardsNumber" placeholder="请输入省级获奖数" />
        </el-form-item>
        <el-form-item label="教师专利数" prop="teacherPatentNumber">
          <el-input v-model="form.teacherPatentNumber" placeholder="请输入教师专利数" />
        </el-form-item>
        <el-form-item label="学生专利数" prop="studentPatentNumber">
          <el-input v-model="form.studentPatentNumber" placeholder="请输入学生专利数" />
        </el-form-item>
        <el-form-item label="三大检索论文数" prop="threeRetrievalPapers">
          <el-input v-model="form.threeRetrievalPapers" placeholder="请输入三大检索论文数" />
        </el-form-item>
        <el-form-item label="核心刊物论文数" prop="coreJournalPapers">
          <el-input v-model="form.coreJournalPapers" placeholder="请输入核心刊物论文数" />
        </el-form-item>
        <el-form-item label="负责人" prop="chargePerson">
          <el-input v-model="form.chargePerson" placeholder="请输入负责人" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { importData,listEquipment, getEquipment, delEquipment, addEquipment, updateEquipment, exportEquipment } from "@/api/statistics/statisticsEquipment";

export default {
  name: "StatisticsEquipment",
  props: {
    detailList: Array,
    baseCollegeId: Number
  },
  data() {
    return {
      upload: {
        open: false,
        isUploading: false,
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/statistics/equipment/importData?baseCollegeId=" + this.baseCollegeId
      },
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 贵重仪器设备表格数据
      statisticsEquipmentList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        baseCollegeId: null,
        orgCode: null,
        number: null,
        classifyNumber: null,
        name: null,
        price: null,
        model: null,
        specs: null,
        teachHours: null,
        scientificHours: null,
        socialServiceHours: null,
        openUserHours: null,
        sampleNumber: null,
        trainStudentNumber: null,
        trainTeacherNumber: null,
        trainOtherNumber: null,
        teachProjectNumber: null,
        scientificProjectNumber: null,
        socialServiceProjectNumber: null,
        nationalAwardsNumber: null,
        provincialAwardsNumber: null,
        teacherPatentNumber: null,
        studentPatentNumber: null,
        threeRetrievalPapers: null,
        coreJournalPapers: null,
        chargePerson: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        baseCollegeId: [
          { required: true, message: "学院高基ID不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    importTemplate() {
      window.open(process.env.VUE_APP_BASE_API + "/statistics/equipment/importTemplate")
    },
    handleImport() {
      this.upload.open = true
    },
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
      this.$emit("refresh");
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },
    /** 查询贵重仪器设备列表 */
    getList() {
      this.loading = true;
      listEquipment(this.queryParams).then(response => {
        this.statisticsEquipmentList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        baseCollegeId: null,
        orgCode: null,
        number: null,
        classifyNumber: null,
        name: null,
        price: null,
        model: null,
        specs: null,
        teachHours: null,
        scientificHours: null,
        socialServiceHours: null,
        openUserHours: null,
        sampleNumber: null,
        trainStudentNumber: null,
        trainTeacherNumber: null,
        trainOtherNumber: null,
        teachProjectNumber: null,
        scientificProjectNumber: null,
        socialServiceProjectNumber: null,
        nationalAwardsNumber: null,
        provincialAwardsNumber: null,
        teacherPatentNumber: null,
        studentPatentNumber: null,
        threeRetrievalPapers: null,
        coreJournalPapers: null,
        chargePerson: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加贵重仪器设备";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getEquipment(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改贵重仪器设备";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateEquipment(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
              this.$emit("refresh");
            });
          } else {
            addEquipment(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除贵重仪器设备编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delEquipment(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有贵重仪器设备数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportEquipment(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
